const util = require("../../../utils/util.js");

const app = getApp()
var that;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderList: [],
    refreshLish: "false"
  },

  /**
   * 生命周期函数--监听页面加载
   */
  // 数据加载
  onLoad: function () {
    that = this;
    this.$wuxToast = app.wux(this).$wuxToast;
    this.setData({
      refreshLish: "true"
    });

    that.refreshNewData();
  },
  // 下拉刷新页面
  onPullDownRefresh: function () {
    this.refreshNewData();
    wx.stopPullDownRefresh();
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  // 进入详情页面
  orderTapClick: function (e) {
    var index = e.currentTarget.dataset.index;
    var orderList = this.data.orderList;
    var currentOrder = orderList[index];
    var urlLink = currentOrder.taskType;
    var taskId = currentOrder.taskId;
    var taskTime = currentOrder.taskTime;
    var taskAddress = currentOrder.recvAddress;
    var taskStatus = currentOrder.taskStatus;
    var taskStatusText = currentOrder.taskStatusText;
    var installFee = currentOrder.installFee;
    var current_userViewId = currentOrder.keyUserViewId;
    var local_adminUserViewId = wx.getStorageSync('adminUserViewId');

    // 进入任务详情页面
    wx.navigateTo({
      url: '../houseSurveyDetail/houseSurveyDetail?id=' + taskId + '&taskStatusText=' + taskStatusText
    });
  },
  //刷新数据
  refreshNewData: function () {
    util.showLoading();
    var urlStr = '/api/task/survey';
    util.request(urlStr, "", function (res) {
      console.log("data===" + res.data.code);
      util.hideToast();
      var msg = res.data.msg;
      if (res.data.code === 200) {
        var newList = res.data.data;
        console.log("newList===" + newList);
        var i = 0;
        if (newList != null) {
          newList.forEach(function (e) {
            var orderType = e.taskStatusText;
            if (orderType == "等待准备物料" || orderType == "准备物料中") {
              e.taskType = "task_material";
            } if (orderType == "等待勘测") {
              e.taskType = "task_houseSurvey";
            } if (orderType == "等待维护") {
              e.taskType = "task_equipmentMaintenance";
            } if (orderType == "等待安装") {
              e.taskType = "task_doorInstallation";
            } if (orderType == "等待滤网维护") {
              e.taskType = "task_filterMaintenance";
            }
            // 更换数据
            newList[i] = e;
            i++;
          });
          // 给数组赋值
          that.setData({
            orderList: newList
          });
        }
      }
    })
  }
})